//
//  ShowMenuView.m
//  EMMApp
//
//  Created by Mac on 16/5/10.
//  Copyright © 2016年 YiXun. All rights reserved.
//

#import "MenuLitsView.h"
#import "MenuCell.h"
@interface MenuLitsView ()<UITableViewDelegate,UITableViewDataSource>
{
    NSString *indetStr;
    BOOL _isShow;
    NSInteger guoduH;
}

@property (nonatomic, copy) NSArray *numArr;

@property (nonatomic, strong) UITableView *tableView;


@end

@implementation MenuLitsView

- (id)initWithFrame:(CGRect)frame
              items:(NSArray *)items
              indet:(NSString *)indet
           isShowUI:(BOOL)isShowUI
              guodu:(NSInteger)guodu {
    if (self == [super initWithFrame:frame]) {
        self.numArr = items;
        guoduH = guodu;
        indetStr = indet;
        _isShow = isShowUI;
        [self showUI];
    }
    return self;
}

#pragma 创建视图初始化
- (void)showUI {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, EMM_HEIGHT)];
    view.backgroundColor = [UIColor clearColor];
    view.userInteractionEnabled = YES;
    [self addSubview:view];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
    [view addGestureRecognizer:tap];
    
    UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, guoduH)];
    subView.backgroundColor = [UIColor whiteColor];
    subView.userInteractionEnabled = YES;
    [self addSubview:subView];
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, subView.frame.size.width, subView.frame.size.height) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [subView addSubview:_tableView];
   
}

#pragma 点击阴影视图消失
- (void)tapClick:(UITapGestureRecognizer *)tap {
    if (_menuLitsBlock) {
        _menuLitsBlock(@"",@"");
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   
    return self.numArr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellId = @"MenuCellId";
    MenuCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"MenuCell" owner:self options:nil] lastObject];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10, 49.5, EMM_WIDTH-20, 0.5)];
    view.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
    [cell addSubview:view];
    
    if (_isShow == YES) {
        cell.menuName.text = [_numArr objectAtIndex:indexPath.row];
        if ([indetStr isEqualToString:[NSString stringWithFormat:@"%ld",indexPath.row]]) {
            
            cell.menuName.textColor = [UIColor colorFromHexCode:@"#FF7200"];

            cell.munInameView.image = [UIImage imageNamed:@"xm_icon"];
            
            cell.gxImageView.image = [UIImage imageNamed:@"pub_duihao"];
        }else {
            cell.menuName.textColor = [UIColor lightGrayColor];
            cell.munInameView.image = [UIImage imageNamed:@"xzXm"];
            cell.gxImageView.image = [UIImage imageNamed:@""];
        }
    }else {
        if ([indetStr isEqualToString:[NSString stringWithFormat:@"%ld",indexPath.row]]) {

            cell.nameNume.textColor = [UIColor colorFromHexCode:@"#FF7200"];

            cell.gxImageView.image = [UIImage imageNamed:@"pub_duihao"];
        }else {
            cell.nameNume.textColor = [UIColor lightGrayColor];
            cell.gxImageView.image = [UIImage imageNamed:@""];
        }
        cell.nameNume.text = [_numArr objectAtIndex:indexPath.row];
    }
    

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *str1 = [_numArr objectAtIndex:indexPath.row];
    NSString *str2 = [NSString stringWithFormat:@"%ld", indexPath.row];
    if (_menuLitsBlock) {
        _menuLitsBlock(str1,str2);
    }
}


@end
